/****************************************************************************

Force Engine v0.5

Creado: 28/03/08
Clase: Game.cpp
Hecho by: German Battiston AKA Melkor

****************************************************************************/

//---------------------------------------------------------------------------
#include "Game.h"
#include <sstream>
//---------------------------------------------------------------------------
using namespace std;
//---------------------------------------------------------------------------
Game::Game(HINSTANCE hInstance)
:
m_hInstance(hInstance),
m_pkInput(NULL),
m_pkCurrentScene(NULL),
m_pkTimer(new Timer()),
m_pkGraphics(new Graphics()),
m_pkWindow(new Window(hInstance))
{
	/*****/
}
//---------------------------------------------------------------------------
Game::~Game()
{
	delete m_pkGraphics;
	m_pkGraphics = NULL;

	delete m_pkWindow;
	m_pkWindow = NULL;

	delete m_pkTimer;
	m_pkTimer = NULL;
}
//---------------------------------------------------------------------------
bool Game::Init()
{
	SetCursor(NULL);

	if(!m_pkWindow->MakeWindow(800, 600))
	{
		return false;
	}

	if(!m_pkGraphics->InitDX(m_pkWindow))
	{
		return false;
	}

	m_pkInput = new DirectInput(m_pkWindow->m_hInstance, m_pkWindow->m_hWnd);

	if(!m_pkInput->Init())
	{
		return false;
	}

	if(!OnInit())
	{
		return false;
	}

	m_pkTimer->FirstMeasure();

	return true;
}
//---------------------------------------------------------------------------
bool Game::Loop()
{
	assert(m_pkTimer);

	m_pkTimer->Measure();

 	m_pkInput->Reacquire();

	//m_pkGraphics->Clear();

	OnLoop();

	// Nombre del Engine y Frames Per Second

	stringstream ss;

	ss << "Force Shader 3D v1.0 Beta - FPS: " << m_pkTimer->GetFPS();

	m_pkWindow->SetWindowTitle(ss.str().c_str());

	return true;
}
//---------------------------------------------------------------------------
bool Game::DeInit()
{
	m_pkInput->DeInit();
	delete m_pkInput;
	m_pkInput = NULL;

	return true;
}

//---------------------------------------------------------------------------